package com.shirley.customcontrols;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.shirley.android.buttongroup.ButtonGroupItemBean;
import com.shirley.android.buttongroup.ButtonGroupView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 按钮组菜单控件fragment
 * Created by ZLJ on 2017/12/18.
 */
public class ButtonGroupFragment extends Fragment {

    Unbinder unbinder;
    @BindView(R.id.button_group_view)
    ButtonGroupView buttonGroupView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_button_group, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        buttonGroupView.setData(constructData());
        buttonGroupView.setButtonOnClickListener(new ButtonGroupView.ButtonOnClickListener() {
            @Override
            public void setButtonClickListener(int position, ButtonGroupItemBean bean) {
                Toast.makeText(getContext(), bean.getDesc(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    private List<ButtonGroupItemBean> constructData(){
        List<ButtonGroupItemBean> data = new ArrayList<>();
        ButtonGroupItemBean button1 = new ButtonGroupItemBean();
        button1.setDesc("button1");
        button1.setUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1576646859429&di=7b27a37cd0db2b8a9b583af23ccae854&imgtype=0&src=http%3A%2F%2Fbpic.588ku.com%2Felement_origin_min_pic%2F16%2F08%2F20%2F2357b8781a8b798.jpg%2521%2Ffwfh%2F804x804%2Fquality%2F90%2Funsharp%2Ftrue%2Fcompress%2Ftrue");
        button1.setNewMessage(0);
        data.add(button1);
        ButtonGroupItemBean button2 = new ButtonGroupItemBean();
        button2.setDesc("button2");
        button2.setUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1576646886036&di=c5beca3a6ec1b05299130e0ef87d0468&imgtype=0&src=http%3A%2F%2Fpic32.nipic.com%2F20130815%2F13448116_171112689000_2.jpg");
        button2.setNewMessage(1);
        data.add(button2);
        ButtonGroupItemBean button3 = new ButtonGroupItemBean();
        button3.setDesc("v");
        button3.setUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1577241615&di=9324a77979c38ef2cb4ae8141b15d3ff&imgtype=jpg&er=1&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2Ffeccd1d805d4f7bb3c4759f0850793b3b4f8bfca5bba-bg6Bom_fw658");
        button3.setNewMessage(2);
        data.add(button3);
        ButtonGroupItemBean button4 = new ButtonGroupItemBean();
        button4.setDesc("button4");
        button4.setUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1576646909520&di=07fd1d8fce9236ef1de456ee01750af2&imgtype=0&src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F02%2F20%2F78%2F59afd40516240_610.jpg");
        data.add(button4);
        ButtonGroupItemBean button5 = new ButtonGroupItemBean();
        button5.setDesc("button5");
        button5.setUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1576646926061&di=1b97cb999d6294d954745d548f439f02&imgtype=0&src=http%3A%2F%2Fku.90sjimg.com%2Felement_origin_min_pic%2F01%2F40%2F32%2F98573cf75c3bf04.jpg");
        data.add(button5);
        ButtonGroupItemBean button6 = new ButtonGroupItemBean();
        button6.setDesc("button6");
        button6.setUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1576646937054&di=e8542f340015e6a025870ac10d6b4d71&imgtype=0&src=http%3A%2F%2Fpic.90sjimg.com%2Fdesign%2F01%2F54%2F03%2F90%2F5930149711114.png");
        data.add(button6);
        return data;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

}
